package Offer;

import java.util.Deque;
import java.util.LinkedList;

/*
* 包含min函数的栈
* */
public class Offer30MinStack {
    /** initialize your data structure here. */
    Deque<Integer> stack1;
    Deque<Integer> stack2;

    public Offer30MinStack() {
        stack1=new LinkedList<Integer>();
        stack2=new LinkedList<Integer>();
    }

    public void push(int x) {
        stack1.push(x);
        // stack2为空时也要加入
        if(stack2.isEmpty() || x<=stack2.peek()){
            stack2.push(x);
        }
    }

    public void pop() {
        int x=stack1.pop();
        if(x==stack2.peek()){
            stack2.pop();
        }
    }

    public int top() {
        return stack1.peek();
    }

    public int min() {
        return stack2.peek();
    }
}
